package com.example.zluserservice.common.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author zhenliu（孙凌岳）
 * @Description AI-获取IP
 * @Date 2025/6/19 18:17
 * @Version 1.0
 */
public class IpUtil {

    public static String getClientIp(HttpServletRequest request) {
        String ip = request.getHeader("X-Forwarded-For");
        if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
            return ip.split(",")[0];
        }
        ip = request.getHeader("Proxy-Client-IP");
        if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
            return ip;
        }
        ip = request.getHeader("WL-Proxy-Client-IP");
        if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
            return ip;
        }
        ip = request.getRemoteAddr();
        return ip;
    }

    public static String getIP(){return "127.0.0.1";};
}